﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RoutingDaemon.Utilities;
using RoutingDaemon.Entities;

namespace RoutingDaemon.ServerInterface.CommandHandlers
{
    class ADDUSERCommandHandler : CommandHandlerBase
    {
        public override string HandleCommand(global::RoutingDaemon.ServerInterface.Commands.DaemonCommandBase command)
        {
            if (command is Commands.ADDUSERCommand)
            {
                Commands.ADDUSERCommand addUserCommand = (Commands.ADDUSERCommand)command;

                if (string.IsNullOrEmpty(addUserCommand.Nickname))
                {
                    return "Error";
                }
                // Add the nick to the local users list
                User newUser = new User()
                {
                    Nickname = addUserCommand.Nickname
                };
                Backend.DaemonBackEnd.Instance.LocalNode.Users.Add(newUser);
                return Responses.GetResponse(ResponseCodes.OK, string.Empty);
            }
            else
            {
                throw new ArgumentException();
            }
        }
    }
}
